package com.eshop.eshopmanagersystem.idal;

import com.eshop.eshopmanagersystem.dal.OrderDAL;
import com.eshop.eshopmanagersystem.model.OrderBarcodesRelationshipInfo;
import com.eshop.eshopmanagersystem.model.OrderInfo;
import com.eshop.eshopmanagersystem.unti.Pager;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 订单功能接口
 */
@Mapper
@Component
public interface IOrderDAL {
    /**
     * 后台查询订单分页
     * 参数1：startIndex
     * 参数2：pageSize
     */
    @Select("select * from order_tb,user_tb where order_tb.user_id=user_tb.user_id order by order_id desc limit #{startIndex},#{pageSize}")
    public List<OrderInfo> getOrderByPager(Pager pager);

    /**
     * 后台查询订单分页数据总条数
     */
    @Select("select count(*) from order_tb")
    public Integer getOrderTotalNum();

    /**
     * 带条件查询的订单分页功能
     * 关键字 @order_code @startIndex @pageSize
     * 返回 查询结果
     */
    @Select("select * from order_tb,user_tb where order_tb.user_id=user_tb.user_id and order_code = #{order_code} order by order_id desc limit #{startIndex},#{pageSize}")
    public List<OrderInfo> getOrderByPagerAndOrderCode(Pager pager);

    /**
     * 带条件查询的订单分页数据总条数
     * 关键字 @order_code     *
     */
    @Select("select count(*) from order_tb WHERE order_code = #{order_code} ")
    public Integer getOrderTotalNumByOrderCode(Pager pager);

    /**
     * 订单分页的order_id查询订单和产品关系
     */
    @Select("select * from order_barcodes_rel,barcodes where order_barcodes_rel.id = barcodes.id and order_id = #{order_id}")
    public List<OrderBarcodesRelationshipInfo> getOrderDetailsByOrderID(OrderInfo orderInfo);

    /**
     *  订单管理
     *  批量删除订单
     *  参数：id的集合
     */
    @Delete("DELETE FROM order_tb where order_id in (${ids})")
    public Integer deleteOrder(OrderInfo orderInfo);

    /**
     * 订单管理
     * 删除订单关系表
     */
    @Delete("delete from order_barcodes_rel where order_id in (${ids})")
    public Integer deleteOrderAndProductRelatonShip(OrderInfo orderInfo);
}
